home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1998 November / Cd users extra 14.iso / prog / inst / mailc / bcast.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-14  |  4.3 KB  |  154 lines

  1. /*
  2. **  BCAST.C [edit EMAIL.H before compiling]
  3. **
  4. **  This is a WIN32 console mode program that sends
  5. **  the same email to a list of email addresses read
  6. **  from a file of addresses. 
  7. */
  8.  
  9. #include <windows.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13.  
  14. #include "see.h"
  15. #include "email.h"
  16.  
  17. // Email the file BCAST.MAI to each address
  18. // as listed in the file BCAST.EML
  19.  
  20. #define EMAIL_ADDR_LIST "BCAST.EML"
  21. #define EMAIL_SUBJECT   "Advisory"
  22. #define EMAIL_FILENAME  "BCAST.MAI"
  23.  
  24. #define MAX_BUF 512
  25. static char Buffer[MAX_BUF];
  26.  
  27. void ErrorExit(int Code)
  28. {seeErrorText(Code,(LPSTR)Buffer,512);
  29.  printf("%s\n", Buffer);
  30.  exit(0);
  31. }
  32.  
  33. /* read text line (ending with LF) from disk */
  34.  
  35. static int ReadTextLine(int Handle, LPSTR Buffer, int BufLen)
  36. {char Ch;
  37.  int  i;
  38.  int  Size = 0;
  39.  static char TextBuffer[128];
  40.  static int  TextLeft = 0;
  41.  static int  TextRight = 0;
  42.  while(1)
  43.    {/* is TextBuffer[] empty ? */
  44.     if(TextLeft>=TextRight)
  45.       {/* read from disk */
  46.        TextLeft = 0;
  47.        TextRight = _lread(Handle,(LPSTR)TextBuffer,125) - 1;
  48.        if(TextRight<0) return -1;
  49.       }
  50.     /* copy till LF or end of buffer */
  51.     for(i=TextLeft;i<=TextRight;i++)
  52.       {Ch = TextBuffer[i];
  53.        /* throw away CRs */
  54.        if(Ch!='\r') 
  55.          {if((Ch=='\n')||(Size==BufLen-1))
  56.             {/* found LF or buffer is full */
  57.              Buffer[Size] = '\0';
  58.              TextLeft = i + 1;
  59.              return Size;
  60.             }
  61.           else
  62.             {/* save char */
  63.              Buffer[Size++] = 0x7f & Ch;
  64.             }
  65.          }
  66.       }
  67.     /* used up all of TextBuffer[] */
  68.     TextLeft = TextRight;
  69.    } /* end-while */
  70. }
  71.  
  72.  
  73. /*** main ***/
  74.  
  75. void main(int argc, char *argv[])
  76. {int i, n;
  77.  int Code; 
  78.  int RcptHandle;
  79.  static char FileName[65];
  80.  
  81.  /* open list of addresses file */
  82.  RcptHandle = _lopen((LPSTR)EMAIL_ADDR_LIST,OF_READ|OF_SHARE_DENY_WRITE);
  83.  if(RcptHandle<0)
  84.    {printf("ERROR: Cannot open %s",EMAIL_ADDR_LIST);
  85.     exit(1);
  86.    }
  87.   
  88.  /* display parameters */
  89.  printf("Server : %s\n",(LPSTR)SMTP_HOST_NAME);
  90.  printf("  From : %s\n",(LPSTR)YOUR_EMAIL_ADDR);
  91.  printf("  Subj : %s\n",(LPSTR)EMAIL_SUBJECT);
  92.  printf("  List : %s\n",(LPSTR)EMAIL_ADDR_LIST); 
  93.  printf("  File : %s\n",(LPSTR)EMAIL_FILENAME); 
  94.  
  95.  Code = seeVerifyFormat((LPSTR)YOUR_EMAIL_ADDR);
  96.  if(Code<0) 
  97.    {printf("%s: ",(LPSTR)YOUR_EMAIL_ADDR );
  98.     ErrorExit(Code);
  99.    }
  100.  
  101.  /* ask permission to continue */
  102.  printf("\nType CR to continue or ^C to abort...");
  103.  getchar(); printf("\n"); 
  104.  
  105.  /* define diagnostics log file */
  106.  ///seeStringParam(SEE_LOG_FILE, (LPSTR)"bcast.log");  
  107.  puts("Connecting...");
  108.  Code = seeSmtpConnect(
  109.     (LPSTR)SMTP_HOST_NAME,                     /* SMTP server */
  110.     (LPSTR)YOUR_EMAIL_ADDR,                    /* our return email address */
  111.     (LPSTR)NULL);                              /* Reply-To header */
  112.  if(Code<0) ErrorExit(Code);
  113.  /* read each email address in turn */
  114.  for(i=1;;i++)
  115.    {/* read next email destination address */
  116.     n = ReadTextLine(RcptHandle, (LPSTR)Buffer, MAX_BUF);   
  117.     if(n<=0) break;
  118.     /* enclose in <> brackets if necessary */
  119.     if(strchr(Buffer,'<')) strncpy(FileName, Buffer, 64);
  120.     else
  121.       {/* enclose in <> brackets */
  122.        strcpy(FileName,"<");
  123.        strcat(FileName,Buffer);
  124.        strcat(FileName,">");
  125.       }
  126.     /* check email address */
  127.     Code = seeVerifyFormat((LPSTR)FileName);
  128.     if(Code>=0)
  129.       {printf("%3d: Mailing to '%s'\n", i, FileName);    
  130.        /* send next email  */
  131.        Code = seeSendEmail(
  132.          (LPSTR)FileName,                 /* To list */
  133.          (LPSTR)NULL,                     /* CC list */
  134.          (LPSTR)NULL,                     /* BCC list */
  135.          (LPSTR)EMAIL_SUBJECT,            /* subject */
  136.          (LPSTR)EMAIL_FILENAME,           /* email filename */
  137.          (LPSTR)NULL);                    /* no attachment */                
  138.        if(Code<0) ErrorExit(Code);
  139.       }
  140.    else
  141.       {/* display error message */ 
  142.        printf("%3d: ",i);
  143.        seeErrorText(Code,(LPSTR)Buffer,MAX_BUF);
  144.        printf("%s in '%s'\n", Buffer, FileName);
  145.       }
  146.    } /* end-for */
  147.      
  148.  puts("All email sent."); 
  149.  _lclose(RcptHandle);
  150.  seeClose(); 
  151. } /* end main */
  152.  
  153.  
  154.